#ifndef REGEXVALIDATOR_H
#define REGEXVALIDATOR_H

#include "stringvalidator.h"
#include "pretreatmenthandler.h"

class RegexValidator : public StringValidator
{
public:
    RegexValidator();
    RegexValidator(const QString& pattern, const QString& errorMsg = "Regex match failed")
        : m_pattern(pattern), m_errorMsg(errorMsg) {}

    ValidationResult validate(const QString& input,
                              const std::vector<ValidationOption>& options = {}) const override {
        QString processed = PretreatmentHandler:: preprocess(input, options);
        QRegularExpression regex(m_pattern);

        if (PretreatmentHandler::shouldApplyOption(options, CaseInsensitive)) {
            regex.setPatternOptions(QRegularExpression::CaseInsensitiveOption);
        }

        if (regex.match(processed).hasMatch()) {
            return ValidationResult(true);
        }
        return ValidationResult(false, m_errorMsg.arg(m_pattern));
    }

private:
    QString m_pattern;
    QString m_errorMsg;
};

#endif // REGEXVALIDATOR_H
